package com.zisuyi.uilibrary

import androidx.appcompat.app.AppCompatActivity
import com.weilele.mvvm.utils.activity.getResBool
import com.yizisu.library.ad.IAd
import com.zisuyi.game.sdk.game.GameEgret
import com.zisuyi.game.sdk.game.GameReceiveMessage
import com.zisuyi.game.sdk.game.bean.AndroidJsBean
import com.zisuyi.game.sdk.utils.UserData
import com.zisuyi.uilibrary.module.activty.game.spin.SpinGameActivity
import com.zisuyi.uilibrary.module.activty.redeem.RedeemActivity
import com.zisuyi.uilibrary.module.dialog.SettingDialog
import com.zisuyi.uilibrary.uitils.SoundUtils

object GameMessage : Function2<AndroidJsBean, GameEgret, Unit> {
    fun createAdImpl(
        appCompatActivity: AppCompatActivity,
        isNeedBanner: Boolean = false,
        isNeedInterstitial: Boolean = false,
    ): IAd {
        return IAd.invoke(appCompatActivity)
    }

    override fun invoke(bean: AndroidJsBean, egret: GameEgret) {
        when (bean.type) {
            GameReceiveMessage.ON_CREATE -> {//egret对象创建
                egret.gameAd = createAdImpl(
                    egret.appCompatActivity,
                    isNeedBanner = true,
                    isNeedInterstitial = false
                )
            }
            GameReceiveMessage.ON_DESTROY -> {//egret对象销毁

            }
            GameReceiveMessage.TYPE_SHOW_SETTING_DIALOG -> {//显示设置对话框
                SettingDialog.show()
            }

            GameReceiveMessage.TYPE_USER_GAME_INFO -> {//用户信息

            }
            GameReceiveMessage.TYPE_CLICK_BUTTON_SOUND -> {//播放按钮声音
                SoundUtils.play(SoundUtils.GameMusic.Btn.bean)
            }
            GameReceiveMessage.TYPE_VIBRATE -> {
                SoundUtils.play(SoundUtils.GameMusic.HaQian.bean)
            }
            GameReceiveMessage.TYPE_CLICK_RIGHT -> {
                SoundUtils.play(SoundUtils.GameMusic.DoubleCoin.bean)
            }
            GameReceiveMessage.TYPE_OPEN_REDEEM_PAGE -> {//打开兑换
                RedeemActivity.start(egret.appCompatActivity)
            }
            GameReceiveMessage.TYPE_OPEN_SPIN_PAGE -> {//打开转盘游戏
                SpinGameActivity.start(egret.appCompatActivity)
            }
            else -> {
            }
        }
    }
}